<!-- 装修用户组件：用户订单 -->
<template>
	<view  class="ss-order-menu-wrap ss-flex ss-col-center" :style="[style, { marginLeft: `${data.space}px` }]">
		<view class="menu-item ss-flex-1 ss-flex-col ss-row-center ss-col-center" v-for="item in dataList.userTypeList"
			:key="item.title" >
      <button  v-if="item.type === 'contact'"  class="custom-contact-button" open-type="contact">
        <uni-badge class="uni-badge-left-margin" :text="numDataList.orderCount[item.count]" absolute="rightTop"
          size="small">
          <image class="item-icon" :src="sheep.$url.static(item.icon)" mode="aspectFit" />
        </uni-badge>
        <view  class="menu-title ss-m-t-20">{{ item.title }}</view>
      </button>
      <view @tap="goPath(item)" v-else style="text-align: center;">
        <uni-badge class="uni-badge-left-margin" :text="numDataList.orderCount[item.count]" absolute="rightTop"
                   size="small">
          <image class="item-icon" :src="sheep.$url.static(item.icon)" mode="aspectFit" />
        </uni-badge>
        <view  class="menu-title ss-m-t-20">{{ item.title }}</view>
      </view>

		</view>
	</view>
</template>

<script setup>
	/**
	 * 装修组件 - 订单菜单组
	 */
	import sheep from '@/sheep';
  import { WxaSubscribeTemplate } from '@/sheep/helper/const';
	import {
		computed
	} from 'vue';
  import OrderApi from '@/sheep/api/trade/order';

	// 接收参数
	const props = defineProps({
		// 装修数据
		data: {
			type: Object,
			default: () => ({}),
		},
		// 装修样式
		styles: {
			type: Object,
			default: () => ({}),
		},
	});
  const numDataList = computed(()=>sheep.$store('user').numData)
	const dataList = computed(()=>sheep.$store('user').orderMap)

  const goPath = async (item) => {
      // if (item.path === '/pages/order/reservationList' || item.path === '/pages/order/adminReservationList') {
      //   // #ifdef MP
      //   await sheep.$platform
      //     .useProvider('wechat')
      //     .subscribeMessage(WxaSubscribeTemplate.NEW_ORDER_APPOINT_SUCCESS);
      //   // #endif
      //   sheep.$router.go(item.path, { type: item.value });
      //   return
      // }else
      if (item.path === '/pages/order/cellOrder/list') {
              // #ifdef MP
              await sheep.$platform
                  .useProvider('wechat')
                  .subscribeMessage([
                      WxaSubscribeTemplate.WXA_ORDER_APPOINTMENT_TRANSACTION_COMPLETE,
                      WxaSubscribeTemplate.WXA_ORDER_APPOINTMENT_PRODUCTION_COMPLETE,
                      WxaSubscribeTemplate.WXA_ORDER_APPOINTMENT_AUDIT_REJECT
                  ]);
              // #endif
              sheep.$router.go(item.path, { type: item.value });
              return
      }else if (item.path === '/pages/order/productionOrder/list' || item.path === '/pages/order/auditOrder/list') {
          // #ifdef MP
          await sheep.$platform
              .useProvider('wechat')
              .subscribeMessage([
                  WxaSubscribeTemplate.WXA_ORDER_APPOINTMENT_AUDIT,
                  WxaSubscribeTemplate.WXA_ORDER_APPOINTMENT_PRODUCTION
              ]);
          // #endif
          sheep.$router.go(item.path, { type: item.value });
          return
      }else if(item.path === '/pages/scan/index') {
        //打开扫一扫
        uni.scanCode({
          onlyFromCamera: true, // 可选，是否只允许摄像头扫码
          success: (res) => {
            console.log('扫码结果：', res.result);
            getOrderInfo(res.result);//
          },
          fail: (err) => {
            console.log('扫码失败', err);

          }
        });
        return;
      }else if(item.path === '/pages/customer/list/my-list') {

        // #ifdef MP
        await sheep.$platform
          .useProvider('wechat')
          .subscribeMessage(WxaSubscribeTemplate.ACCOUNT_CHANGE_SUCCESS);
        // #endif

        sheep.$router.go(item.path, { type: item.value });
        return
      }

    sheep.$router.go(item.path, { type: item.value });
  }

  const getOrderInfo = async (code) => {
   let res =  await OrderApi.getByPickUpVerifyCode({pickUpVerifyCode: code});
   if(res.code === 0) {
       let id = res.data.id
       sheep.$router.go('/pages/order/verifyOrderDetail', {
         id,
       });
   }else{
     uni.showToast({
       title: '未查询到订单信息',
       icon: 'none'
     });
   }
  };


	// 设置背景样式
	const style = computed(() => {
		// 直接从 props.styles 解构
		const {
			bgType,
			bgImg,
			bgColor
		} = props.styles;
		// 根据 bgType 返回相应的样式
		return {
			background: bgType === 'img' ?
				`url(${bgImg}) no-repeat top center / 100% 100%` : bgColor
		};
	});
</script>

<style lang="scss" scoped>
  .custom-contact-button {
    background: transparent;
    border: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    box-shadow: none;
    font-size: 0;
    color: inherit;
    background:none;
    border: none;
    padding: 0;
    margin:0;
    outline: none;
    // 重置字体相关属性
    font-size: inherit;
    font-family: inherit;
    font-weight: inherit;
    line-height: inherit;
    // 重置盒模型
    box-sizing: border-box;
    width: 100%;
    height: auto;
    // 重置其他可能影响大小的属性
    min-height:0;
    min-width:0;
    //去除button的默认边框和点击效果
    &::after {
      border: none;
    }
    //去除点击时的背景色变化(如果需要的话)
    &:active {
      background: none;
    }
  }

  .ss-order-menu-wrap {
		.menu-item {
			height: 160rpx;
			position: relative;
			z-index: 10;

			.menu-title {
				font-size: 24rpx;
				line-height: 24rpx;
				color: #333333;
			}

			.item-icon {
				width: 44rpx;
				height: 44rpx;
			}

			.num-icon {
				position: absolute;
				right: 18rpx;
				top: 18rpx;
				// width: 40rpx;
				padding: 0 8rpx;
				height: 26rpx;
				background: #ff4d4f;
				border-radius: 13rpx;
				color: #fefefe;
				display: flex;
				align-items: center;

				.num {
					font-size: 24rpx;
					transform: scale(0.8);
				}
			}
		}
	}
</style>
